﻿<UserControl x:Class="MobSoulWPhoneToolkit.Controls.RepeatButton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Coding4Fun="clr-namespace:Coding4Fun.Phone.Controls;assembly=Coding4Fun.Phone.Controls"  
    xmlns:converter="clr-namespace:Coding4Fun.Phone.Controls.Converters;assembly=Coding4Fun.Phone.Controls"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    Width="60" Height="60" >
    <UserControl.Resources>
        <Style x:Key="RepeatButtonStyle1" TargetType="RepeatButton">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
            <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
            <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
            <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
            <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
            <Setter Property="Padding" Value="10,3,10,5"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RepeatButton">
                        <Grid Background="Transparent">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver"/>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneBackgroundBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="ButtonBackground" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0" Background="Transparent">
                                <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <converter:ThemedImageConverter x:Key="ThemedImageConverter" />
        <System:String x:Key="PlusImagePath">/MobSoulWPhoneToolkit;component/Assets/RepeatButton/{0}/appbar.add.rest.png</System:String>
        <System:String x:Key="MinusImagePath">/MobSoulWPhoneToolkit;component/Assets/RepeatButton/{0}/appbar.minus.rest.png</System:String>
        <System:String x:Key="invPlusImagePath">/MobSoulWPhoneToolkit;component/Assets/RepeatButton/{0}/appbar.inv.add.rest.png</System:String>
        <System:String x:Key="invMinusImagePath">/MobSoulWPhoneToolkit;component/Assets/NumerRepeatButtonicUpDown/{0}/appbar.inv.minus.rest.png</System:String>
    </UserControl.Resources>
    <Grid>
        <Grid>
            <Ellipse Name="Ellipse" StrokeThickness="5"  >
                <Ellipse.Stroke>
                    <SolidColorBrush Color="{StaticResource PhoneContrastBackgroundColor}" />
                </Ellipse.Stroke>
                <Ellipse.Fill>
                    <SolidColorBrush Color="Transparent"/>
                </Ellipse.Fill>
            </Ellipse>
            <Image Name="noPressedMinus" Source="{Binding Source={StaticResource MinusImagePath}, 
			        Converter={StaticResource ThemedImageConverter}}" Width="60" Height="60"
                    HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed"/>
            <Image Name="nopressedplus" Source="{Binding Source={StaticResource PlusImagePath}, 
			       Converter={StaticResource ThemedImageConverter}}" 
                   HorizontalAlignment="Center" VerticalAlignment="Center" />
        </Grid>
        <Grid  Name="PressedGrid" Visibility="Collapsed">
            <Ellipse StrokeThickness="5"  >
                <Ellipse.Stroke>
                    <SolidColorBrush Color="{StaticResource PhoneContrastBackgroundColor}" />
                </Ellipse.Stroke>
                <Ellipse.Fill>
                    <SolidColorBrush Color="{StaticResource PhoneContrastBackgroundColor}" />
                </Ellipse.Fill>
            </Ellipse>
            <Image x:Name="pressedMinus"  Source="{Binding Source={StaticResource invMinusImagePath}, 
			        Converter={StaticResource ThemedImageConverter}}" Width="60" Height="60"
                    HorizontalAlignment="Center" VerticalAlignment="Center"  />
            <Image x:Name="pressedPlus" Source="{Binding Source={StaticResource invPlusImagePath}, 
			       Converter={StaticResource ThemedImageConverter}}" 
                   HorizontalAlignment="Center" VerticalAlignment="Center" />
        </Grid>
        <RepeatButton Name="repeatButton" Padding="0" 
                      Style="{StaticResource RepeatButtonStyle1}"
                      BorderThickness="0" Click="Repeated_Click" ManipulationCompleted="repeatButton_ManipulationCompleted" ManipulationStarted="repeatButton_ManipulationStarted">
        </RepeatButton>
    </Grid>
</UserControl>
